<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../../library'),
    realpath(APPLICATION_PATH . '/models'),
    get_include_path(),
)));

//Set timezone
date_default_timezone_set('Asia/Shanghai');

//Set session path
ini_set("session.save_path", dirname(__FILE__) . "/session");

//Register configs
require_once "Zend/Registry.php";
require_once "Zend/Config/Ini.php";
$configs = array(
	'db' => APPLICATION_PATH . '/configs/db.ini',
    'data'=> APPLICATION_PATH . '/configs/data.ini'
);
foreach ($configs as $key => $configPath) {
	$config = new Zend_Config_Ini($configPath, APPLICATION_ENV);
	$registry = Zend_Registry::getInstance()->set($key, $config);
}
//deal with the quotes problem
if (ini_get('magic_quotes_gpc')) {
	function stripslashesRecursive(array $array)
	{
		foreach ($array as $k => $v) {
			if (is_string($v)) {
				$array[$k] = stripslashes($v);
			} else if (is_array($v)) {
				$array[$k] = stripslashesRecursive($v);
			}
		}
		return $array;
	}

	$_GET     = stripslashesRecursive($_GET);
	$_POST     = stripslashesRecursive($_POST);
}

/** Zend_Application */
require_once 'Zend/Application.php';
require_once "Zend/Loader/Autoloader.php";
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();